﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class ViewALLUnScheduleCourse : System.Web.UI.Page
    {
        ViewManager manager=new ViewManager();
        DataTable table=new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack!=true)
            {
                PopulatedDepartmentDropDownList();
               
            }

        }
        private void PopulatedSemesterDropDownList()
        {
            SemesterManager semesterManager = new SemesterManager();
            DataTable semesters = semesterManager.GetAllSemester();
            semesterDropDownList.DataTextField = "SemesterName";
            semesterDropDownList.DataValueField = "Id";
            semesterDropDownList.DataSource = semesters;
            semesterDropDownList.DataBind();
        }

        private void PopulatedDepartmentDropDownList()
        {
            DepartmentManager departmentManager = new DepartmentManager();
            DataTable departments = departmentManager.GetAllDepartments();
            departmentDropDownList.DataTextField = "Name";
            departmentDropDownList.DataValueField = "Id";
            departmentDropDownList.DataSource = departments;
            departmentDropDownList.DataBind();
        }


        protected void showButton_Click(object sender, EventArgs e)
        {
            string selectDepartment = departmentDropDownList.SelectedValue;
            string selectSemester = semesterDropDownList.SelectedValue;
            string message1;
            string message2;
            string courseNotFound = null;
            try
            {
                string outMessage = null;
                    if (selectDepartment != "" && selectSemester != "")
                    {
                         table = manager.GetAllUnscheduleCourseForDePartmentIdAndSemesterId(selectDepartment,selectSemester, out message1);
                        outMessage = message1;
                    }
                    else if (selectDepartment != "" && selectSemester == "")
                    {
                        table = manager.GetUnScheduleCourseForDepartment(selectDepartment, out message2);
                        outMessage = message2;
                    }
                             
                viewUnScheduleCourseGridView.DataSource = table;
                viewUnScheduleCourseGridView.DataBind();
                viewMessageLabel.ForeColor = Color.Indigo;
                viewMessageLabel.Text = outMessage;
                if(table.Rows.Count==0)
                {
                    courseNotFound = "No Unscheduled Courses";
                    viewMessageLabel.Text = string.Empty;
                    viewMessageLabel.ForeColor = Color.DeepPink;
                    viewMessageLabel.Text = courseNotFound;
                }

            }
            catch (Exception exception)
            {

                viewMessageLabel.ForeColor = Color.Red;
                viewMessageLabel.Text = exception.Message;
            }
        }

        protected void yesRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            PopulatedSemesterDropDownList();
            noRadioButton.Checked = false;
            noRadioButton.Text = string.Empty;
        }

        protected void NoRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            PopulatedYesButton();
        }
        private void PopulatedYesButton()
        {
            yesRadioButton.Checked = false;
            yesRadioButton.Text = string.Empty;
            semesterDropDownList.DataTextField = string.Empty;
            semesterDropDownList.DataValueField = string.Empty;
            semesterDropDownList.DataSource = string.Empty;
            semesterDropDownList.DataBind();
        }
        
    }
}